package com.iwayin.core.bo.task;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.iwayin.core.bo.BaseBO;
import com.iwayin.core.bo.EmailServiceUtil;
import com.iwayin.core.dataobject.AskDO;
import com.iwayin.core.dataobject.UserDO;

public class DayHotAskTaskBOImpl extends BaseBO implements DayHotAskTaskBO{
	/**
	 * 发送邮件
	 * @param receivers
	 * @param asks
	 */
	public void sendTopVote5AskEmail(List<UserDO> receivers, List<AskDO> asks) {
		if (asks.size() == 0) 
			return;
		Random rand=new Random();
		this.loger.info("send top5 email size:" + receivers.size());
		for(UserDO user : receivers) {
			Map<String, Object> params = new HashMap<String, Object>();
			AskDO ask = asks.get(rand.nextInt(asks.size()));
			params.put("userName", user.getNickname());
			params.put("askId", ask.getId().toString());
			params.put("askInfo", ask.getQuestion());
			params.put("askPic", ask.getPicPath());
			EmailServiceUtil.sendTopVote5Email(user.getLoginName(), params);
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				this.loger.error("send top5 email waiting is interrupted");
			}
		}
	}

	@Override
	public void sendTopLike5AskEmail(List<UserDO> receivers, List<AskDO> asks) {
		if (asks.size() == 0) 
			return;
		Random rand=new Random();
		this.loger.info("send top5 email size:" + receivers.size());
		for(UserDO user : receivers) {
			Map<String, Object> params = new HashMap<String, Object>();
			AskDO ask = asks.get(rand.nextInt(asks.size()));
			params.put("userName", user.getNickname());
			params.put("askId", ask.getId().toString());
			params.put("askInfo", ask.getQuestion());
			params.put("askPic", ask.getPicPath());
			EmailServiceUtil.sendTopLike5Email(user.getLoginName(), params);
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				this.loger.error("send top5 email waiting is interrupted");
			}
		}
	}
}
